Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax version verification #44

Merged
merged 5 commits into from
Apr 9, 2021

Conversation

caioaamaral
Copy link
Contributor

Signed-off-by: Caio Amaral [email protected]

🦟 Bug fix

Fixes #36

Summary

Relax the --force-version verification method. Now it's not necessary to specify the fully-qualified version, instead if only the major version is passed, commands will be tested against the major version only.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

@github-actions github-actions bot added 🏢 edifice Ignition Edifice 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome labels Mar 21, 2021
@caioaamaral
Copy link
Contributor Author

I confess I've got a bit lost on how to write a test for this fix (neither figure out where are the tests), but if desired I can write one.

@caioaamaral
Copy link
Contributor Author

@caguero friendly ping

@caioaamaral
Copy link
Contributor Author

@chapulina @caguero friendly ping

@caguero
Copy link
Contributor

caguero commented Apr 5, 2021

@caioaamaral , I'll review your PR this week. Thanks for your contribution!

Copy link
Contributor

@caguero caguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit hesitant to change the behavior of this option. Specially because we might have situations where two major versions are installed and we want to choose one of them. If we apply this patch we'll lose the ability to do it.

I'd be open to add a new option --force-major-version that ignores the patch number. See my next comment instead.

Copy link
Contributor

@caguero caguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also check the discussion on issue #36 please? There's a good suggestion by @chapulina for keeping just the --force-version argument but allowing multiple values:

  • Just a major version. E.g.: --force-version 9
  • Major and minor. E.g.: --force-version 9.1
  • Full version (current behavior). E.g.: --force-version 9.1.0

@caioaamaral
Copy link
Contributor Author

caioaamaral commented Apr 5, 2021

Could you also check the discussion on issue #36 please? There's a good suggestion by @chapulina for keeping just the --force-version argument but allowing multiple values:

* Just a major version. E.g.: `--force-version 9`

* Major and minor. E.g.: `--force-version 9.1`

* Full version (current behavior). E.g.: `--force-version 9.1.0`

This change is expected to behave just like this. I'm splitting the version used as input into different fields (based on the number of '.'), then just those fields will be used when checking against the library version.

Ex:

required_version = '9.1'
library version = '9.1.3'

will check only two first fields of version, if they matches then this is the one that will be used.

This is achieved by this change on the current implementation:

    required_version = required_version.split('.')
    version = version.split('.')
    next unless required_version.zip(version).map {|required, current| required == current}.all?

if required_version has different size than version, required_version.zip(version) will have required_version size, ignoring the last fields from version

@caguero
Copy link
Contributor

caguero commented Apr 6, 2021

Could you also check the discussion on issue #36 please? There's a good suggestion by @chapulina for keeping just the --force-version argument but allowing multiple values:

* Just a major version. E.g.: `--force-version 9`

* Major and minor. E.g.: `--force-version 9.1`

* Full version (current behavior). E.g.: `--force-version 9.1.0`

This change is expected to behave just like this. I'm splitting the version used as input into different fields (based on the number of '.'), then just those fields will be used when checking against the library version.

Ex:

required_version = '9.1'
library version = '9.1.3'

will check only two first fields of version, if they matches then this is the one that will be used.

This is achieved by this change on the current implementation:

    required_version = required_version.split('.')
    version = version.split('.')
    next unless required_version.zip(version).map {|required, current| required == current}.all?

if required_version has different size than version, required_version.zip(version) will have required_version size, ignoring the last fields from version

Thanks for the clarification!

Copy link
Contributor

@caguero caguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick experiment:

caguero@frost:~/workspace/ign-tools/build$ ign topic -l --force-version 9
Traceback (most recent call last):
	3: from /usr/bin/ign:236:in `<main>'
	2: from /usr/bin/ign:236:in `each_with_index'
	1: from /usr/bin/ign:236:in `each'
/usr/bin/ign:238:in `block in <main>': undefined method `split' for #<Array:0x00005576a168c2d0> (NoMethodError)
caguero@frost:~/workspace/ign-tools/build$ ign topic -l --force-version 9.1
Traceback (most recent call last):
	3: from /usr/bin/ign:236:in `<main>'
	2: from /usr/bin/ign:236:in `each_with_index'
	1: from /usr/bin/ign:236:in `each'
/usr/bin/ign:238:in `block in <main>': undefined method `split' for #<Array:0x00005558fd413a60> (NoMethodError)
ign topic -l --force-version 9.1.0
Traceback (most recent call last):
	3: from /usr/bin/ign:236:in `<main>'
	2: from /usr/bin/ign:236:in `each_with_index'
	1: from /usr/bin/ign:236:in `each'
/usr/bin/ign:238:in `block in <main>': undefined method `split' for #<Array:0x00005592b8143ef8> (NoMethodError)

Do you get the same error?

@caioaamaral
Copy link
Contributor Author

caioaamaral commented Apr 6, 2021


Do you get the same error?

My mistake, sorry for the noise. Just forced push edd8b16 which will solve this problem.

Running locally using gazebo command (please ignore the XDG warning, gazebo opened just fine):
Edit: gazebo version is 3.8.0

orise@caioaamaral-Nabuchadnezzar:bin$ ./ign gazebo --force-version 3
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-orise'
orise@caioaamaral-Nabuchadnezzar:bin$ ./ign gazebo --force-version 3.1
Version error: I cannot find this command in version [3.1].
orise@caioaamaral-Nabuchadnezzar:bin$ ./ign gazebo --force-version 3.8
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-orise'
orise@caioaamaral-Nabuchadnezzar:bin$ ./ign gazebo --force-version 3.8.0
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-orise'
orise@caioaamaral-Nabuchadnezzar:bin$ ./ign gazebo --force-version 3.8.1
Version error: I cannot find this command in version [3.8.1].

Copy link
Contributor

@caguero caguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! It works for me as expected when I provide a version that matches my installed library. However it produces an exception when the library is not found, as opposed to show the error message "I cannot find the library...". E.g.:

ign topic -l --force-version 12
Traceback (most recent call last):
	3: from /usr/bin/ign:236:in `<main>'
	2: from /usr/bin/ign:236:in `each_with_index'
	1: from /usr/bin/ign:236:in `each'
/usr/bin/ign:237:in `block in <main>': undefined method `split' for ["12"]:Array (NoMethodError)
ign topic -l --force-version 12.1.2
Traceback (most recent call last):
	3: from /usr/bin/ign:236:in `<main>'
	2: from /usr/bin/ign:236:in `each_with_index'
	1: from /usr/bin/ign:236:in `each'
/usr/bin/ign:237:in `block in <main>': undefined method `split' for ["12", "1", "2"]:Array (NoMethodError)

@caioaamaral
Copy link
Contributor Author

Thanks for the changes! It works for me as expected when I provide a version that matches my installed library. However it produces an exception when the library is not found, as opposed to show the error message "I cannot find the library...". E.g.:

Strange, I can't reproduce this error:

orise@caioaamaral-Nabuchadnezzar:bin$ ./ign topic -l --versions
8.2.0
orise@caioaamaral-Nabuchadnezzar:bin$ ./ign topic -l --force-version 12
Version error: I cannot find this command in version [12].
orise@caioaamaral-Nabuchadnezzar:bin$ ./ign topic -l --force-version 12.1.2
Version error: I cannot find this command in version [12.1.2].

Maybe your binary is missing my last update?

@caguero
Copy link
Contributor

caguero commented Apr 8, 2021

Strange, I can't reproduce this error:

I think I know what's happening. My guess is that you only have one version of Ignition Transport installed. The problem seems to be here:

commands[ARGV[0]].each_with_index do |version, index|
    required_version = required_version.split('.')

Originally, required_version is a String and you can call split(). However you're overwriting required_version with the result of the split(), converting it to an Array. The next time you iterate in the loop (only if you have more than one version), split fails because it's not declared for Array types.

My suggestion is to use a separate local variable for the result of split(). As a bonus point, you'll also avoid to call join() later in case you need to print the error message.

@caioaamaral
Copy link
Contributor Author

caioaamaral commented Apr 8, 2021

Strange, I can't reproduce this error:

I think I know what's happening. My guess is that you only have one version of Ignition Transport installed. The problem seems to be here:

commands[ARGV[0]].each_with_index do |version, index|
    required_version = required_version.split('.')

Originally, required_version is a String and you can call split(). However you're overwriting required_version with the result of the split(), converting it to an Array. The next time you iterate in the loop (only if you have more than one version), split fails because it's not declared for Array types.

My suggestion is to use a separate local variable for the result of split(). As a bonus point, you'll also avoid to call join() later in case you need to print the error message.

Got it, thanks for the clarification.
Edit: e473b66 applies your suggestion

Signed-off-by: Caio Amaral <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Copy link
Contributor

@caguero caguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me! I took the liberty of moving one line outside of the loop. Thanks for the patch!

@caguero
Copy link
Contributor

caguero commented Apr 9, 2021

I confess I've got a bit lost on how to write a test for this fix (neither figure out where are the tests), but if desired I can write one.

It's OK, for now we only have a static code checker test. There was a minor issue fixed in ce44884.

@caguero caguero merged commit 1925384 into gazebosim:ign-tools1 Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel 🔮 dome Ignition Dome 🏢 edifice Ignition Edifice
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--force-version could be more flexible
2 participants